@extends('layouts.back_stage')
@section('content')
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/parameters.css?v=1.0.1">
    <div class="container">
        <div class="parameter-btn">
            <h3 style="float:left;">业务参数</h3>
            <a class="btn-a" href="/admin/craft_code">工艺名称</a>
            <a class="btn-a" href="/admin/saleSeason">销售季节</a>
            <a class="btn-a" href="/admin/sizeSetting">尺码组设置</a>
            <a class="btn-a" href="javascript:;" style="background:#27c24c;">品牌设置</a>
        </div>
        <ul class="parameter-ul">
            {{--品牌设置--}}
            <li id="trademark" class="parameter-li" style="display:block;">
                <div class="parameter-choose">
                    <span>共<span class="in_count">{{$brands_count}}</span>条信息</span>
                    <a class="btn bt_a btn-primary" href="javascript:;" onclick="addBrand()">添加</a>
                </div>
                <div class="brand_tab">
                    <table class="brand" border="1" cellspacing="0" cellpadding="0">
                        <tr></td><td>品牌名称</td><td>操作</td></tr>
                        @foreach($brands as $k=>$v)
                            <tr class="amend_{{ $v->id }}">
                                <td class='brand-name'>{{ $v->brand_name }}</td>
                                <td>
                                    <a href="javascript:;" onclick="amendBrand({{ $v->id }})">修改</a>
                                    {{--<a href="javascript:;" onclick="delBrand({{ $v->id }})">删除</a>--}}
                                </td>
                            </tr>
                        @endforeach
                    </table>
                    <span style="float:right;">{{$brands->links()}}</span>
                </div>
            </li>
        </ul>
    </div>
    {{--遮罩层--}}
    <div class="mask" style="display:none;"></div>
    {{--品牌设置弹框--}}
    <div class="popup" style="display:none;height:210px;">
        <div class="popup_header">
            <span>品牌名称</span>
            <button class="shut1 shut">×</button>
        </div>
        <div class="popup_center">
            <input class="popup_inp inp2" maxlength="10" type="text" autocomplete="off" autocorrect="off" placeholder="品牌名称(必)" />
        </div>
        <div class="popup_bottom">
            <button class="popup_btn">确定</button>
        </div>
    </div>
    <script>
        //业务参数
        //拖拽
        function drag(id1,id2){
            var mouseOffx = 0;
            var mouseOffy = 0;
            var isDrag = false;
            $(id1).unbind(".click").on("mousedown", function (ev) {
                if( $(".tz-datepicker").is(":hidden") ){	//自己添加
                    $(".tz-datepicker").hide();
                }else{
                    $(".tz-datepicker").hide();
                }
                mouseOffx = ev.clientX - $(id1).offset().left;
                mouseOffy = ev.clientY - $(id1).offset().top;
                isDrag = true;
            })
            $(document).unbind(".click").on("mousemove", function (ev) {
                var mourseX = ev.clientX, mourseY = ev.clientY;
                var moveX = 0, moveY = 0;
                if (isDrag === true) {
                    moveX = mourseX - mouseOffx;
                    moveY = mourseY - mouseOffy;
                    var maxX = $(window).outerWidth(false) - $(id2).outerWidth(false);
                    var maxY = $(window).outerHeight(false) - $(id2).outerHeight(false);
                    moveX = Math.min(maxX, Math.max(0, moveX));
                    moveY = Math.min(maxY, Math.max(0, moveY));
                    $(id2).css({ "left": moveX, "top": moveY });
                }
            });
            $(document).unbind(".click").on("mouseup", function () {
                isDrag = false;
            });
        }
        drag(".popup_header",".popup");
        drag(".sell_header",".sell");
        //品牌设置js
        //点击添加按钮
        function addBrand(){
            $(".popup_btn").addClass("sure1").removeClass("sure2")  ;
            $(".inp2").val("");
            $(".popup").show();
            $(".mask").show();
        }
        //点击确定按钮
        $(document).on("click",".sure1",function(){
            var val2=$(".inp2").val();
            if(val2==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填写品牌名称");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".popup").hide();
            $(".mask").hide();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                url:'/admin/brandName/store',
                type:'post',
                data:{
                    'name':val2
                },
                dataType:'json',
                success:function (data) {
                    if(data.success == true){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("添加成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
        //点击关闭按钮
        $(".shut1").click(function(){
            $(".popup").hide();
            $(".mask").hide();
        });
        //删除
        function delBrand(id){
            $(".oText").text("确定要删除吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','oDelete');
        }
        /*点确定*/
        $(document).on('click','#oDelete',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/admin/brandName/destroy',
                data:{
                    'id':id
                },
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("删除成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        //修改
        function amendBrand(id){
            $(".popup_btn").addClass("sure2").removeClass("sure1");
            $(".popup").show();
            $(".mask").show();
            $(".popup_btn").attr("def",id);
            $(".inp2").val( $('.amend_'+id).children(".brand-name").text() );
        }
        $(document).on("click",".sure2",function(){
            var m2=$(".inp2").val();
            if(m2==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("品牌名称不能为空");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".popup").hide();
            $(".mask").hide();
            var id=$(".sure2").attr("def");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/admin/brandName/update',
                data:{
                    'name':m2,
                    'id': id
                },
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("修改成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
    </script>
    {{--    <script src="{{env('CDN_DOMAIN_NAME')}}/js/parameters.js?v=1.0.2"></script>--}}
@endsection